<template>
  <el-dialog
      v-model="houseAddWinDialogVisible"
      title="新增仓库设置"
      width="60%"
      @close="handleClose"
      draggable
      center
  ><!-- draggable表示可以拖动弹窗-->
    <template #default>
      <el-form :model="newHouse">
        <el-form-item label="仓库编码">
          <el-input v-model="newHouse.houseEncode"/>
        </el-form-item>
        <el-form-item label="仓库名称">
          <el-input v-model="newHouse.houseName"/>
        </el-form-item>
        <el-form-item label="仓库位置">
          <el-input v-model="newHouse.houseLocation"/>
        </el-form-item>
        <el-form-item label="面积">
          <el-input v-model="newHouse.houseArea"/>
        </el-form-item>
        <el-form-item label="负责人">
          <el-input v-model="newHouse.houseHead"/>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="newHouse.houseRemark"/>
        </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="addHouseSubmit" type="primary">提交</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import {ref, watch} from "vue";
import houseRequest from "@/api/house.js";

let newHouse = ref({});
const props = defineProps(['flag']);
const emits = defineEmits(['cancelAdd','addComplete'])
let houseAddWinDialogVisible = ref(false);

/**
 * 关闭窗体前的回调函数
 */
function handleClose(){
  newHouse = ref({});
  emits("cancelAdd");
}
function cancel(){
  newHouse = ref({});
  emits("cancelAdd");
}
/**
 * 新增点检项目的提交按钮事件
 */
function addHouseSubmit() {
  houseRequest.insert(newHouse.value, res => {
    emits("addComplete");
    houseAddWinDialogVisible.value = false;
  })
}

// 属性侦听
watch(() => props.flag, () => {
  houseAddWinDialogVisible.value = props.flag === 1;
});
</script>
<style scoped>

</style>